// 创建数据库连接
const mysql = require("mysql")
const connection = mysql.createConnection({
    host: "47.112.241.166",
    port: 3306,
    user: "blog",
    password: "tG7sNMA6DKzjAs2F",
    database: "blog"
})
connection.connect((err) => {
    console.log(err,'rree');
    if (err) { console.log("连接失败") }
    else { console.log("连接成功") }
})
 
let query=(sql, callback)=>{
    connection.query(sql, function (err, rows) {
        callback(err, rows);
    });
    // connection.end();//end()的话好像就只能连接一次的样子
}
 
// 创建连接池，连接池和创建数据库连接的区别目前还没搞懂
// const pool=mysql.createPool({
//     host:"101.132.36.129",
//     port:3306,
//     user:"root",
//     password:"123456",
//     database:"sentence"
// });
 
// let query=(sql,callback)=>{
//     pool.getConnection((err,connection)=>{
//         console.log(connection)
//         connection.query(sql,(err,rows)=>{
//             callback(err,rows);
//             connection.release()
//         })
//     })
// }
 
exports.query = query